<?php
/**
 * Open Framework
 *
 * LICENSE
 *
 *this file is a template.
 *
 *
 * @category   
 * @package    
 * @subpackage 
 * @copyright  copyright
 * @license    $Id: file.php 5308 2008-12-13 17:18:45Z fy $
 */

/**
 * Fy_Tpl_Abstract 
 *
 * @category   
 * @package    
 * @subpackage 
 * @copyright  
 * @license    
 */
class FreeY_View extends FreeY_View_Abstract
{
	/**
	 * display page
	 *
	 * @param $tpl string 
	 * @return echo
	 */
	public function display($tpl)
	{
		$this->tpl = $tpl;
		echo $this->_getHtml();
	}

	/**
	 *  return Html
	 *
	 * @return Html string
	 */
	protected function _getHtml()
	{
		if(is_array($this->vars))
		{
			foreach($this->vars as $key => $value)
			{
				$$key = $value;
			}
		}
		ob_start();
		include $this->_getTplPath();
		return ob_get_clean();
	}
	/**
	 * get tpl file path
	 *
	 * @return tpl file path
	 */
	protected function _getTplPath()
	{
		return $this->templates_dir . $this->tpl;
	}
	
	/**
	 * assign vars
	 *
	 * @param $key mix vars.key
	 * @param $value mix vars[$key].value default null
	 * @return set self::$vars or return self::$vars[$key]
	 */
	public function assign($key, $value = null)
	{
		if($value === null) return $this->vars[$key];
		$this->vars[$key] = $value;
	}

	/**
	 * get lbi path
	 *
	 * @param $lbi_name lbi name
	 * @return lbi_path
	 */
	protected function _getLbiPath($lbi_name)
	{
		return dirname($this->_getTplPath()) . DS . 'lbi' . DS . $lbi_name . '.lbi';
	}
	
	/**
	 * get last lbi path
	 *
	 * @param $lbi_name lbi name
	 * @param $last_num last num
	 * @return lbi_path
	 */
	protected function _getLastLbiPath($lbi_name, $last_num = 1)
	{
		$last_dir = dirname($this->_getTplPath());
		$last_num = intval($last_num);
		if($last_num < 1)
			$last_num = 1;
		for($i = 0; $i < $last_num; $i++)
		{
			$last_dir = dirname($last_dir . '.php');
		}
		return  $last_dir . DS . 'lbi' . DS . $lbi_name . '.lbi';
	}
	
	/**
	 * assign Attribute
	 *
	 * @param $key mix Attribute.key
	 * @param $value mix Attribute.value default null
	 * @return set Attribute or return Attribute
	 */
	public function assignAttribute($key, $value = null)
	{
		if($value === null) return $this->$key;
		$this->$key = $value;
	}

}//class end ******
//file end--------------------------------------------------------->
?>